<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */
namespace Plugin\Alarm\Http\Request\Admin;

use Hyperf\Validation\Request\FormRequest;

/**
 * 报警消息类型验证数据类
 */
class RdAlarmTypeRequest extends FormRequest
{
    /**
     * 场景配置
     */
    protected array $scenes = [
        'index' => [
            'id', 'name', 'voice_id', 'type', 'sort', 'level', 'risk_title', 'risk_text', 'risk_level', 'expire_time', 'icon', 'created_by', 'created_at', 'updated_at'
        ],
        'create' => [
            'name', 'voice_id', 'type', 'sort', 'level', 'risk_title', 'risk_text', 'risk_level', 'expire_time', 'icon'
        ],
        'update' => [
            'name', 'voice_id', 'type', 'sort', 'level', 'risk_title', 'risk_text', 'risk_level', 'expire_time', 'icon'
        ],
        'delete' => [ 'id', 'ids' ],
    ];

    public function authorize(): bool
    {
        return true;
    }


    /**
     * 新增数据验证规则
     * return array
     */
    public function rules(): array
    {
        return [
            'id' => 'integer|min:1',
            'ids' => 'array|min:1',
            'ids.*' => 'integer|min:1',

            'name' => 'nullable|string|max:255',
            'voice_id' => 'integer|min:0',
            'type' => 'required|integer|in:1,2',
            'sort' => 'integer|min:0',
            'level' => 'required|integer|in:1,2,3,4',
            'risk_level' => 'required|integer|in:1,2,3',
            'risk_title' => 'nullable|string|max:255',
            'risk_text' => 'nullable|string|max:255',
            'expire_time' => 'nullable|integer|min:0',
            'icon' => 'nullable|string|max:255',
            'created_by' => 'integer|min:1',
            'updated_by' => 'integer|min:1',
        ];
    }


    /**
     * 字段映射名称
     * return array
     */
    public function attributes(): array
    {
        return [
            'name' => '消息名',
            'voice_id' => '语音播报ID',
            'type' => '类型',
            'sort' => '排序',
            'level' => '风险等级',
            'risk_level' => '工单紧急程度',
            'risk_title' => '预警信息标题',
            'risk_text' => '预警文本',
            'expire_time' => '工单整改限时',
            'icon' => '图标',
            'created_by' => '创建者',
            'updated_by' => '更新者',

        ];
    }

public function messages(): array
{
    return [
            'id.required' => '必填',
            'name.required' => '必填消息名',
            'voice_id.required' => '必填语音播报ID',
            'type.required' => '必填类型',
            'type.in' => '类型只能是1(摄像机)或2(雷达)',
            'sort.required' => '必填排序',
            'level.required' => '必填风险等级',
            'level.in' => '风险等级只能是1(创建工单)、2(喊话处理)、3(需查看)或4(预警)',
            'risk_level.required' => '必填工单紧急程度',
            'risk_level.in' => '工单紧急程度只能是1(一般)、2(紧急)或3(非常紧急)',
            'risk_title.max' => '预警信息标题最大长度为255个字符',
            'risk_text.max' => '预警文本最大长度为255个字符',
            'expire_time.integer' => '工单整改限时必须是整数',
            'expire_time.min' => '工单整改限时不能为负数',
            'icon.max' => '图标最大长度为255个字符',
            'created_by.required' => '必填创建者',
            'updated_by.required' => '必填更新者',

    ];
}
}